import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base/base/base_container.dart';
import 'package:flutter_base/resource/theme/dark_mode_provider.dart';
import 'package:flutter_base/utils/loading_utils.dart';
import 'package:provider/provider.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    Loading.ctx = context;
    WidgetsBinding.instance.addObserver(this);
    _initAsync();
  }

  Future<void> _initAsync() async {
    await SpUtil.getInstance();
    setTheme(context);
  }

  @override
  void didChangePlatformBrightness() {
    super.didChangePlatformBrightness();
    // 设置初始化主题颜色
    setTheme(context);
  }

  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<DarkModeProvider>(builder: (context, appInfo, _) {
      return BaseContainer();
    });
  }
}
